package cn.net.dpi.lock.autoconfigure;

import cn.net.dpi.lock.support.Lock;
import cn.net.dpi.lock.support.RedisLock;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class DpiLockAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean({ Lock.class })
    @ConditionalOnBean({ StringRedisTemplate.class })
    public Lock defaultRedisLock(StringRedisTemplate stringRedisTemplate) {

        return new RedisLock(stringRedisTemplate);
    }
}
